#include <GLee.h>
#include "GuiLabel.h"
#include "FontManager.h"
#include <iostream>
#ifdef DEBUG_NEW
#include "debug/debug_new.h"
#endif

GuiLabel::GuiLabel() {
    _text = "";
}

GuiLabel::GuiLabel(string text) {
    _text = text;
}

GuiLabel::GuiLabel(GuiRect* rect, GuiProp* prop, GLuint texture, GLuint bg_texture) : GuiWidget(rect, prop, texture, bg_texture) {

}

GuiLabel::GuiLabel(string text, GuiRect* rect, GuiProp* prop, GLuint texture, GLuint bg_texture) : GuiWidget(rect, prop, texture, bg_texture) {
    _text = text;
}

GuiLabel::~GuiLabel() {
}

void GuiLabel::_build_display(FontManager* font) {
    if (_text != "") {
        if (_display) {
            glDeleteLists(_display, 1);
        }
        _display = glGenLists(1);
        int* v = _rect->value();
        float mw, mh;
        glNewList(_display, GL_COMPILE);
        glColor3fv(_prop->color);
        font->render(_text, v[GUI_X], v[GUI_Y], v[GUI_W], v[GUI_H], _prop->zindex + 0.5f, _prop->align, _prop->valign, &mw, &mh);
        glEndList();
    }
}